package com.qfedu.mbtiapi.service.impl;

import com.qfedu.mbtiapi.dao.QuestionDao;
import com.qfedu.mbtiapi.entity.Question;
import com.qfedu.mbtiapi.service.QuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 测试题表(Question)表服务实现类
 *
 * @author makejava
 * @since 2024-11-01 10:53:40
 */
@Service("questionService")
public class QuestionServiceImpl implements QuestionService {
    @Resource
    private QuestionDao dao;

    /**
     * 查询测试的测试题
     * @param utid 测试id*/
    @Override
    public List<Question> queryByUtid(Integer utid) {
        return dao.selectByUtid(utid);
    }
    /**
     * 回答测试题
     * @param id 测试题id
     * @param answer 回答内容*/
    @Override
    public String updateAnswer(Integer id, String answer) {
        //查询对应的编号
        Question question=dao.selectById(id);
        String realAnswer="";
        if(answer.equals("a")){
            realAnswer= question.getAnswera();
        }else if(answer.equals("b")) {
            realAnswer=question.getAnswerb();
        }else {
            return "请选择对应的选项！";
        }
        if(dao.updateAnswer(id,realAnswer)>0){
            return "回答问题成功";
        }

        return "亲，回答问题失败！";
    }
}
